/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Description: dlna controller
 * Author: 
 * Create: 2023-10-20
 */

#include <iterator>
#include "cast_engine_log.h"
#include "dmr_listener.h"
#include "dmr_manager.h"
#include "dlna_controller.h"
#include "dlna_common.h"

namespace OHOS {
namespace CastEngine {
namespace CastEngineService {
DEFINE_CAST_ENGINE_LABEL("Cast-Dlna-Controller");

DmrManager DlnaController::dmrManager_ = DmrManager::GetInstance();

DlnaController& DlnaController::GetInstance()
{
	static DlnaController instance;
	return instance;
}

DlnaController::DlnaController()
{
}

void DlnaController::SetDlnaListener(std::shared_ptr<IDlnaListener> listener)
{
    listener_ = listener;
}

bool DlnaController::ProcessRenderReadyRequest()
{
    CLOGD("Process render ready request in.");
    //return listener_->OnPlayerReady("123", 1);
    return true;
}


bool DlnaController::DmrCreate()
{
	auto DmrListener = DmrListener::GetInstance();
    DmrListener.RegisterDmrListener(listener_);
	dmrManager_.Init();
	dmrManager_.Create("12:34:45:56:56:78");
    CLOGD("Out");

    return true;
}

bool DlnaController::DmrDestroy()
{
    dmrManager_.Destroy();
    dmrManager_.DeInit();
    listener_ = nullptr;
    return true;
}

bool DlnaController::SendEventChange(int moduleId, int event, const std::string &param)
{
    CLOGD("SendEventChange:%{public}d %{public}d %{public}s",moduleId, event, param.c_str());
	auto dmrListener = DmrListener::GetInstance();
    dmrListener.SendEventChange(moduleId, event, param);
	return true;
}

bool DlnaController::GetDlnaDeviceName(std::string &deviceName)
{
    deviceName = dmrManager_.GetDeviceName();
    CLOGD("deviceName:%{public}s",deviceName.c_str());
    return true;
}

bool DlnaController::SetDlnaDeviceName(const std::string &deviceName)
{
    CLOGD("SetDlnaDeviceName:%{public}s",deviceName.c_str());
    if(dmrManager_.SetDeviceName(deviceName.c_str()) == 0) {
        return true;
    } else {
        return false;
    }

}

} // namespace CastEngineService
} // namespace CastEngine
} // namespace OHOS